package com.yx1996.serviceimpl;

import com.yx1996.dao.CustomerDao;
import com.yx1996.dao.LinkManDao;
import com.yx1996.daoimpl.CustomerDaoImpl;
import com.yx1996.daoimpl.LinkManDaoImpl;
import com.yx1996.domain.Customer;
import com.yx1996.domain.LinkMan;
import com.yx1996.service.LinkManService;
import com.yx1996.utils.HibernateUtils;
import org.hibernate.Transaction;

public class LinkManServiceImpl implements LinkManService {
    private LinkManDao lmd = new LinkManDaoImpl();
    private CustomerDao customerDao = new CustomerDaoImpl();
    @Override
    public void add(LinkMan linkMan) {
        //打开事务
        Transaction tx = HibernateUtils.getCurrentSession().beginTransaction();
        try {
            Long cust_id = linkMan.getCust_id();
            Customer customer = customerDao.getById(cust_id);
            linkMan.setCustomer(customer);
            lmd.add(linkMan);
        }catch (Exception e){
            e.printStackTrace();
            tx.rollback();
        }finally {
            tx.commit();
        }
    }
}
